using System.IO;
using System.Windows;
using Bookvar.ObjectModel;
using Bookvar.ObjectModel.Actions;

namespace Bookvar.UI.DragDrop.Actions
{
    public class FileDropAction : TopicDropActionBase
    {
        public override void Execute( CompositeAction compositeAction, TopicContentPresenter presenter, Point dropPoint )
        {
            if ( Data.GetDataPresent( DataFormats.FileDrop ) )
            {
                string[] fileNames = (string[]) Data.GetData( DataFormats.FileDrop );
                if ( fileNames != null && fileNames.Length > 0 )
                {
                    var attachment = new Attachment( Path.GetFileName( fileNames[ 0 ] ) );
                    var addAttachmentAction =
                        TopicActions.CreateAddAttachmentAction(
                            attachment, fileNames[ 0 ], presenter.Topic, presenter.Owner.Mindmap );

                    compositeAction.Add( addAttachmentAction );
                    ActionService.Execute( compositeAction );
                }
            }
        }
    }
}